package com.hxz.mapper;

import java.util.List;

import org.apache.ibatis.annotations.Delete;
import org.apache.ibatis.annotations.Insert;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;

import com.hxz.entity.Article;


public interface ArticleMapper {
	@Select("SELECT a.id,a.title,a.viewnum,a.date,a.content,a.top,a.add_name,a.category,COUNT( * ) AS 'commentnum' FROM article a LEFT JOIN articlecomments b ON a.id = b.articleId GROUP BY a.title ORDER BY a.top DESC, a.date DESC ")
    public List<Article> findAllArticle();

    @Select("SELECT id,title,viewnum,date,content,top,add_name,category FROM article WHERE title LIKE '%${title}%'")
    public List<Article> findByTitleLike(@Param("title") String title);
    
    @Select("SELECT id,title,viewnum,date,content,top,add_name,category FROM `article` WHERE id =#{id}")
	public Article findOne(@Param("id")String id);
    
    @Select("SELECT id,title,viewnum,date,content,top,add_name,category FROM `article` WHERE category =${category}")
	public List<Article> findAllByCategoryName(@Param("category") String category);
    
    @Delete("DELETE  FROM `article` WHERE id =${id}")
	public void delete(@Param("id")String id);
    
    @Insert("INSERT INTO article (title,create_date,content,add_name,category) VALUES(${title},${create_date},${content},${add_name},${category})")
	public void save(Article article);
    
    @Select("SELECT id,title,viewnum,date,content,top,add_name,category from `article` order by viewnum desc limit 0,5")
    public List<Article> hotarticle() ;
    
    @Select("SELECT id,title,viewnum,date,content,top,add_name,category from `article` order by viewnum desc limit 0,3")
	public List<Article> getTop3();
}
